import { Utils } from 'orion-common'
import TEntityNode from './node-entity.js'

class TRootNode extends TEntityNode {
  constructor (config) {
    super(Utils.lodash.merge({
      canMove: false,
      canClose: false,
      protos: { root: true },
      title: '根节点',
      fill: '#DDA0DD'
    }, config))
  }

  /**
   * 
   * @param {*} child 
   */
  addChild (child) {
    if (!child || !this.config.acceptChild) {
      return
    }

    // 将原节点变为子节点
    //let children = this.removeChildren()
    this.childZone.add(child.knode())
    this.children.push(child)
    this.addChildLink()

    // if (children.length > 0) {
    //   for (let c of children) {
    //     child.childZone.add(c.knode())
    //     child.children.push(c)
    //     child.addChildLink()
    //   }
    //   // 自动展开
    //   child.expandChildren(true)
    //   child.adjust({
    //     downward: true,
    //     upward: true
    //   })
    // }

    this.adjust()
  }
}

export default TRootNode
